FROM node:16-alpine AS Front
WORKDIR /web
COPY ./web .
RUN npm install && npm run build

FROM ubuntu:20.04 AS Tongsuo
ARG DEBIAN_FRONTEND=noninteractive
ADD sources.list /etc/apt/
RUN apt-get update \
    && apt-get -y install git curl make gcc\
    && git config --global http.sslverify false \
    && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
    # 安装Tongsuo
    && git clone https://atomgit.com/tongsuo/Tongsuo.git \
    && cd Tongsuo \
    && ./config --prefix=/opt/tongsuo enable-ntls enable-ssl-trace -Wl,-rpath,/opt/tongsuo/lib64 --debug \
    && make -j \
    && make install \
    && /opt/tongsuo/bin/tongsuo version \
    && apt-get -y remove git curl make gcc \
       && apt-get -y autoremove \
       && rm -rf /var/lib/apt/lists/*

FROM golang:1.18 AS BACK
WORKDIR /go/src/app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main
COPY --from=Tongsuo /opt/tongsuo /opt/tongsuo
COPY --from=Front /web/build ./web/build
EXPOSE 8888
CMD ["/go/src/app/main"]
